<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/8/5
 * Time: 14:29
 *
 * 后台分组 普通控制器父类
 *
 */

namespace Tools;


use Think\Controller;

class AdminController extends Controller
{
    function __construct()
    {
        parent::__construct();      //先继承ThinkPHP父类construct

        $nowac=CONTROLLER_NAME."-".ACTION_NAME;

        $admin_id=session('admin_id');
        $admin_name=session('admin_name');

        //未登录用户禁止访问
        $loginac="Manager-login,Manager-verityImg";
        if (empty($admin_name) && strpos($loginac,$nowac)===false){
            $this->redircet('Manager/login');
            exit;
        }



        $manager_info=D('Manager')->find($admin_id);
        $role_id=$manager_info['mg_role_id'];

        $roleinfo=D('Role')->find($role_id);
        $auth_ac=$roleinfo['role_auth_ac'];

        //默认权限
        $allow_ac="Manager-login,Manager-verityImg,Manager-logout,Index-index,Index-left,Index-head,Index-right";


        //权限匹配，匹配操作权限不存在与auth_ac，且不存在于默认权限，且有户名不是admin，则没有访问权限
        if(strpos($auth_ac,$nowac)===false && strpos($allow_ac,$nowac)===false && $admin_name!='admin'){
            exit("没有访问权限！");
        }

    }
}